<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Mac," />





  <link rel="alternate" href="/atom.xml" title="Martin's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="在Amazon上申请一个VPS，然后搭建shadowsocks服务器[1]，Mac上再安装一个ShadowsocksX,我们就可以用socks5代理上网了。 用浏览器是可以上网了，但是如果要在term里面访问外网该怎么办呢？比如用repo更新Android源码。">
<meta name="keywords" content="Mac">
<meta property="og:type" content="article">
<meta property="og:title" content="Mac下如何全方位访问外网">
<meta property="og:url" content="http://martint.oschina.io/2015/12/23/Mac下如何全方位访问外网/index.html">
<meta property="og:site_name" content="Martin&#39;s Blog">
<meta property="og:description" content="在Amazon上申请一个VPS，然后搭建shadowsocks服务器[1]，Mac上再安装一个ShadowsocksX,我们就可以用socks5代理上网了。 用浏览器是可以上网了，但是如果要在term里面访问外网该怎么办呢？比如用repo更新Android源码。">
<meta property="og:updated_time" content="2017-06-18T01:50:53.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Mac下如何全方位访问外网">
<meta name="twitter:description" content="在Amazon上申请一个VPS，然后搭建shadowsocks服务器[1]，Mac上再安装一个ShadowsocksX,我们就可以用socks5代理上网了。 用浏览器是可以上网了，但是如果要在term里面访问外网该怎么办呢？比如用repo更新Android源码。">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://martint.oschina.io/2015/12/23/Mac下如何全方位访问外网/"/>





  <title>Mac下如何全方位访问外网 | Martin's Blog</title>
  














</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Martin's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">每天进步一点</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://martint.oschina.io/2015/12/23/Mac下如何全方位访问外网/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Martin Tang">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Martin's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Mac下如何全方位访问外网</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2015-12-23T11:42:45+08:00">
                2015-12-23
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/技术笔记/" itemprop="url" rel="index">
                    <span itemprop="name">技术笔记</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2015/12/23/Mac下如何全方位访问外网/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2015/12/23/Mac下如何全方位访问外网/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>在Amazon上申请一个VPS，然后搭建shadowsocks服务器<sup><a href="#ref1">[1]</a></sup>，Mac上再安装一个ShadowsocksX,我们就可以用socks5代理上网了。</p>
<p>用浏览器是可以上网了，但是如果要在term里面访问外网该怎么办呢？比如用repo更新Android源码。<br><a id="more"></a></p>
<p>在网上寻找了下，主要有以下2个方法：</p>
<ol>
<li><strong>Proxychains</strong><sup><a href="#ref2">[2]</a></sup>。配置正确了socks5代理，但是不知道为什么在命令行下更新Android源码不行，似乎只有用wget可以，连用curl都不行。于是不得不另寻它法。</li>
<li><strong>Privoxy</strong><sup><a href="#ref3">[3]</a></sup>。这个<strong>Privoxy</strong>可以理解为代理的代理，它将socks5代理转为http代理，然后，设置环境变量就可以访问外网了。</li>
</ol>
<h2 id="Privoxy"><a href="#Privoxy" class="headerlink" title="Privoxy"></a>Privoxy</h2><p>用Mac安装Privoxy十分简单，<code>brew install privoxy</code>。</p>
<p>最好将/usr/local/etc/privoxy目录里的文件拷贝至~/.privoxy，这样你要做什么修改都在~/.privoxy中做，做错了还可以从/usr/local/etc/privoxy找到例子。例子写得十分详尽，如果需要更好地配置，可以好好看看，这里我们就将config修改成以下即可：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div></pre></td><td class="code"><pre><div class="line"># The original config file is /usr/local/etc/privoxy/config</div><div class="line"></div><div class="line">confdir /Users/martint/.privoxy</div><div class="line">logdir /Users/martint</div><div class="line">filterfile default.filter</div><div class="line">logfile privoxy</div><div class="line">actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on.</div><div class="line">actionsfile default.action   # Main actions file</div><div class="line">#actionsfile user.action      # User customizations</div><div class="line"></div><div class="line"># 监听端口为8118</div><div class="line">listen-address  :8118</div><div class="line">toggle  1</div><div class="line">enable-remote-toggle  1</div><div class="line">enable-remote-http-toggle  0</div><div class="line">enable-edit-actions 1</div><div class="line">enforce-blocks 0</div><div class="line">buffer-limit 4096</div><div class="line">forwarded-connect-retries  0</div><div class="line">accept-intercepted-requests 0</div><div class="line">allow-cgi-request-crunching 0</div><div class="line">split-large-forms 0</div><div class="line">keep-alive-timeout 300</div><div class="line">socket-timeout 300</div><div class="line">debug   1    # show each GET/POST/CONNECT request</div><div class="line">debug   4096 # Startup banner and warnings</div><div class="line">debug   8192 # Errors - *we highly recommended enabling this*</div><div class="line">#admin-address privoxy-admin@example.com</div><div class="line">#proxy-info-url http://www.example.com/proxy-service.html</div><div class="line"></div><div class="line"># 由于我们的ss运行于1080端口，我们加入下面的配置，不要忘了最后的点.</div><div class="line">forward-socks5 / 127.0.0.1:1080 .</div></pre></td></tr></table></figure></p>
<p>直接输入<code>privoxy ~/.privoxy/config</code>启动privoxy即可，然后设置http_proxy和https_proxy环境变量为<strong>127.0.0.1:8118</strong>，就可以全方位访问外网了。</p>
<p>为了方便，可以加入如下shell函数到.zshrc：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line">function gfw_free() &#123;</div><div class="line">    DTTERM=`pgrep privoxy`</div><div class="line">    if [ -z &quot;$DTTERM&quot; ]; then</div><div class="line">        privoxy ~/.privoxy/config</div><div class="line">        export http_proxy=127.0.0.1:8118</div><div class="line">        export https_proxy=127.0.0.1:8118</div><div class="line">        echo &quot;Now you can across gfw&quot;</div><div class="line">    else</div><div class="line">        echo &quot;already across gfw...&quot;</div><div class="line">    fi</div><div class="line">&#125;</div><div class="line"></div><div class="line">function gfw_back() &#123;</div><div class="line">    DTTERM=`pgrep privoxy`</div><div class="line">    if [ -n &quot;$DTTERM&quot; ]; then</div><div class="line">        pkill privoxy</div><div class="line">        unset http_proxy</div><div class="line">        unset https_proxy</div><div class="line">        echo &quot;gfw back&quot;</div><div class="line">    else</div><div class="line">        echo &quot;gfw already back...&quot;</div><div class="line">    fi</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>如果需要开机启动，可以输入<code>brew info privoxy</code>，按照提示来操作。</p>
<hr>
<p>参考：</p>
<p>[1]. <a id="ref1"><a href="https://segmentfault.com/a/1190000003101075" target="_blank" rel="external">科学上网之EC2搭建shadowsocks</a></a></p>
<p>[2]. <a id="ref2"><a href="http://shawnelee88.github.io/2015/07/10/proxychains-shadowsocks神器/" target="_blank" rel="external">proxychains+shadowsocks神器</a></a></p>
<p>[3]. <a id="ref3"><a href="https://blog.phpgao.com/privoxy-shadowsocks.html" target="_blank" rel="external">使用Privoxy将socks5代理转为http代理</a></a></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Mac/" rel="tag"># Mac</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/11/19/Android之MediaScanner小结/" rel="next" title="Android之MediaScanner小结">
                <i class="fa fa-chevron-left"></i> Android之MediaScanner小结
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/12/26/Android之AlarmManager如何区分不同的定时器/" rel="prev" title="Android之AlarmManager如何区分不同的定时器">
                Android之AlarmManager如何区分不同的定时器 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2015/12/23/Mac下如何全方位访问外网/"
           data-title="Mac下如何全方位访问外网" data-url="http://martint.oschina.io/2015/12/23/Mac下如何全方位访问外网/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="Martin Tang" />
          <p class="site-author-name" itemprop="name">Martin Tang</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">33</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">4</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">8</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Privoxy"><span class="nav-number">1.</span> <span class="nav-text">Privoxy</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Martin Tang</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"martintang"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  
















  





  

  

  

  

  

  

</body>
</html>
